package cyf.Owner.dao;

import cyf.Owner.bean.CarVo;
import cyf.Owner.bean.OwnerVo;
import cyf.Tools.ServerResponse;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;

@Repository
public class OwnerDaompl implements OwnerDao{
    @Autowired
    public SqlSession sqlSession;

    //获取所有业主信息
    @Override
    public List<OwnerVo> getAllOwner(Map<String, Object> param) {
        List<OwnerVo> owners = sqlSession.selectList("cyf.Owner.dao.OwnerDao.getAllOwner",param);
        return owners;
    }

    //获得记录总行数
    @Override
    public int getRowCount() {
        int count = sqlSession.selectOne("cyf.Owner.dao.OwnerDao.getRowCount");
        return count;
    }

    //获取车辆总数
    @Override
    public int getCarsRowCount(Map<String, Object> param) {
        int count = sqlSession.selectOne("cyf.Owner.dao.OwnerDao.getCarsRowCount",param);
        return count;
    }

    //插入业主信息
    @Override
    public boolean insertOwner(Map<String,Object> param) {
        int success = sqlSession.insert("cyf.Owner.dao.OwnerDao.insertOwner",param);
        if(success!=0)
            return true;
        else
            return false;
    }

    //插入车辆信息
    @Override
    public boolean insertCar(Map<String, Object> param) {
        int success = sqlSession.insert("cyf.Owner.dao.OwnerDao.insertCar",param);
        if(success!=0)
            return true;
        else
            return false;
    }

    //车辆列表获取
    @Override
    public List<CarVo> getCars(Map<String, Object> param) {
        List<CarVo> cars = sqlSession.selectList("cyf.Owner.dao.OwnerDao.getCars",param);
        return cars;
    }
    //根据业主或号码获取车辆列表
    @Override
    public List<CarVo> getCarsByOwner(Map<String, Object> param) {
        List<CarVo> cars = sqlSession.selectList("cyf.Owner.dao.OwnerDao.getCarsByOwner",param);
        return cars;
    }

    //根据车牌号删除一个车辆
    @Override
    public boolean deleteCayByPlate(Map<String, Object> param) {
        int success = sqlSession.delete("cyf.Owner.dao.OwnerDao.deleteCayByPlate",param);
        if(success!=0){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteOwnerBySfz(Map<String, Object> param) {
        int success = sqlSession.delete("cyf.Owner.dao.OwnerDao.deleteOwnerBySfz",param);
        if(success!=0){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteCarByOwner(Map<String, Object> param) {
        int success = sqlSession.delete("cyf.Owner.dao.OwnerDao.deleteCarByOwner",param);
        return true;
    }


}
